package es.luimoco.wishlist;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

public class AddActivity extends Activity {
	private int SELECT_IMAGE = 237487;
	ImageView visorImagen;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.addwish_layout);
		
		visorImagen = (ImageView) findViewById(R.id.visorimagen);
		
		final ImageButton bGaleria = (ImageButton) findViewById(R.id.bgaleria);
		bGaleria.setOnClickListener(new View.OnClickListener() {   
			 public void onClick(View v) {
				 Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
			     intent.setType("image/*");
			     startActivityForResult(intent, SELECT_IMAGE);
			 }
			});
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		try {
			if (requestCode == SELECT_IMAGE)
				if (resultCode == Activity.RESULT_OK) {
					Uri selectedImage = data.getData();
					visorImagen.setImageURI(selectedImage);
				}
			/*if (requestCode == TAKE_PICTURE)
				if (resultCode == Activity.RESULT_OK) {
					Uri selectedImage = data.getData();
					lblPhoto.setText(getPath(selectedImage));
					imgPhoto.setImageURI(selectedImage);
				}*/
		} catch (Exception e) {
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.add, menu);
		return true;
	}

}
